package com.syp.envops.service.impl;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.syp.envops.dao.ServerMapper;
import com.syp.envops.domain.pojo.ServerSchema;
import com.syp.envops.domain.vo.ServerVo;
import com.syp.envops.service.ServerServiceI;

@Service("serverService")
public class ServerServiceImpl implements ServerServiceI {

	@Autowired
	private ServerMapper serverMapper;	
	
	@Override
	public ServerVo get(Integer id) {
		ServerVo server = new ServerVo();
		ServerSchema ss = this.serverMapper.getById(id);
		BeanUtils.copyProperties(ss, server);		
		return server;
	}

	@Override
	public List<ServerVo> list() {
		List<ServerVo> list = new LinkedList<ServerVo>();
		
		List<ServerSchema> serverList = this.serverMapper.getList();
		for(ServerSchema ss : serverList){
			ServerVo server = new ServerVo();			
			BeanUtils.copyProperties(ss, server);
			list.add(server);
		}
		return list;
	}

	@Override
	public void insert(ServerVo server) {
		ServerSchema ss = new ServerSchema();		
		BeanUtils.copyProperties(server, ss);
		this.serverMapper.insert(ss);
        server.setId(ss.getId());
	}

	@Override
	public void delete(Integer id) {
		this.serverMapper.delete(id);
	}

	@Override
	public void edit(ServerVo server) {
		ServerSchema ss = new ServerSchema();		
		BeanUtils.copyProperties(server, ss);		
		this.serverMapper.update(ss);
	}
}
